package com.bjpowernode.dataservice.service.impl;

import com.bjpowernode.api.model.ProductInfo;
import com.bjpowernode.api.service.ProductService;
import com.bjpowernode.api.vo.ProductBidInfo;
import com.bjpowernode.dataservice.mapper.BidInfoMapper;
import com.bjpowernode.dataservice.mapper.ProductInfoMapper;
import com.sun.scenario.effect.Offset;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: panDeng_Zhu
 * @time: 2022/10/24 16:50
 */

@DubboService(interfaceClass = ProductService.class, version = "1.0")
public class ProductServiceImpl implements ProductService {

    @Resource
    private BidInfoMapper bidInfoMapper;

    @Resource
    private ProductInfoMapper productInfoMapper;
    //按照productType分页查询产品
    @Override
    public List<ProductInfo> queryPageByType(Integer productType, Integer pageNo, Integer pageSize) {

        int offset = (pageNo - 1) * pageSize;
        List<ProductInfo> productInfoList = productInfoMapper.selectPageByType(productType, offset, pageSize);
        return productInfoList;
    }

    //按照type查询产品的总数
    @Override
    public Integer queryCountOfProductByType(Integer productType) {

        Integer counts = productInfoMapper.selectCountOfProductByType(productType);
        return counts;
    }

    @Override
    public ProductInfo queryProductByProductId(Integer productId) {
        ProductInfo productInfo = productInfoMapper.selectByPrimaryKey(productId);
        return productInfo;
    }

    //分页查询投资记录
    @Override
    public List<ProductBidInfo> queryBidListByUserId(Integer userId, Integer pageNo, Integer pageSize) {
        if (pageNo == null || pageNo < 1) {
            pageNo = 1;
        }
        if (pageSize == null | pageSize < 0) {
            pageSize = 5;
        }
        int offset = (pageNo - 1) * pageSize;
        List<ProductBidInfo> list = bidInfoMapper.selectBidListByUserId(userId, offset,pageSize);
        return list;
    }
}
